import { defHttp } from "/@/utils/http/axios"
import { useMessage } from "/@/hooks/web/useMessage"
import { getIntoPageTenantId } from "/@/utils/tenant/index"
import { useGlobSetting } from "/@/hooks/setting"

const glob = useGlobSetting()
const { createErrorModal } = useMessage()

export const getLoginUrl = (redirectUri) => {
  const params = {
    pageDomain: window.location.host,
    redirectUri: window.location.protocol + "//" + window.location.host + redirectUri
  }
  return defHttp.get({ url: '/iam-service/login/getLoginUrl', params })
}

export const getImageCaptcha = (captchaType = "image") => defHttp.post({ url: "/iam-service/captcha/get", params: { captchaType } })
export const checkImageCaptcha = (params) => {
  return defHttp.post({ url: "/iam-service/captcha/check", params }, { isTransformResponse: false, errorMessageMode: "none" })
}

export function doLogout() {
  return defHttp.delete({ url: "/iam-service/logout" })
}

export function loginByCode(params) {
  return defHttp.post({ url: "/iam-service/oauth/loginByCode", params}, { isTransformResponse: false})
}

export function checkLogin(params) {
  return defHttp.get({ url: "/iam-service/login/check", params}, { isTransformResponse: false})
}
